package com.xinghou.platform.server.api.controller;

import com.xinghou.platform.entity.req.WeiXinShareReq;
import com.xinghou.platform.server.api.bussiness.WeixinShareService;
import com.xinghou.platform.util.exception.DBExceptionEnums;
import com.xinghou.platform.util.exception.ServiceException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by liufangyu on 2016/7/25.
 */
@Controller
@SessionAttributes("token")
public class WeixinShareController extends  BaseControl {
    @Resource
    private WeixinShareService weixinShareService;
    /**
     * 话题列表
     * @param weiXinShareReq
     * @param request
     * @param response
     * @return
     */
    @ResponseBody
    @RequestMapping(value="/weixinShare",method = {RequestMethod.POST})
    public String weixinShare( @RequestBody WeiXinShareReq weiXinShareReq,
                               HttpServletRequest request, HttpServletResponse response)
    {
        Map<String, String> ret =null;
        try {
            ret =weixinShareService.weixinShare(weiXinShareReq);

            // 注意 URL 一定要动态获取，不能 hardcode
            for (Map.Entry entry : ret.entrySet()) {
                System.out.println(entry.getKey() + ", " + entry.getValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException(DBExceptionEnums.SERVER_INTEERFACE_ERROR);
        }
        return response(ret);
    }

}
